import crudHeaderProperties, { getHeaderProperties } from '@/api/erp/headerProperties'

export const tablemixins = {
  data() {
    return {
      headerInfo: {},
      tableConfigShow: false
    }
  },
  methods: {
    getHead() {
      const data = {
        modelName: this.headerInfo.code,
        url: this.headerInfo.path,
        userId: this.headerInfo.userId
      }
      getHeaderProperties(data).then((res) => {
        this.header = JSON.parse(res.data.header.content)
        this.header = this.header.map(item=>{
          if(item.prop === 'noTaxPrice') {
            item.visibleDisabled = true
          }
          return item
        })
      })
    },
    saveHead() {
      const data = {
        name: this.headerInfo.name,
        code: this.headerInfo.code,
        path: this.headerInfo.path,
        userId: this.headerInfo.userId,
        content: JSON.stringify(this.header)
      }
      crudHeaderProperties.add(data).then(res => {
        this.tableConfigShow = false
      }).catch(err => {
      })
    },
    tableConfig() {
      this.tableConfigShow = true
    },
    changeColWidth(nw, ow, col, evt) {
      const list = this.header
      list.find((item) => item.showName === col.label).width = nw
      this.saveHead()
    },
    columnLabel(obj) {
      if (obj.showName) {
        return obj.showName
      }
      obj.showName = obj.label
      return obj.showName
    }
  }
}
